package com.rabbit.mq.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @version V1.0.0
 * @ClassName: {@link MsgDataUtil}
 * @Description: MsgDataUtil
 * @author: Lanzhou
 * @date: 2021/3/17 11:16
 * @Copyright:2020 All rights reserved.
 */
public class MsgDataUtil {

    public static Map<String, String> buildMsg() {
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        Map<String, String> map = new HashMap<>(3);
        String messageId = String.valueOf(UUID.randomUUID());
        map.put("messageId", messageId);
        map.put("createTime", createTime);
        return map;
    }


    /**
     * {key=value,key=value,key=value} 格式转换成map
     *
     * @param str
     * @param entryNum
     * @return
     */
    public static Map<String, String> mapStringToMap(String str, int entryNum) {
        str = str.substring(1, str.length() - 1);
        String[] split = str.split(",", entryNum);
        Map<String, String> map = new HashMap<String, String>();
        for (String string : split) {
            String key = string.split("=")[0].trim();
            String value = string.split("=")[1];
            map.put(key, value);
        }
        return map;
    }

}
